为了账号安全,请及时绑定邮箱和手机立即绑定

openlayers加载titleGrid

标签:
JavaScript
<!DOCTYPE html>
<html>
<head>
    <title>Canvas Tiles</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.5.0/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="https://openlayers.org/en/v4.5.0/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
    var oUrl="http://10.24.171.34/MERSI/20171116/"+"{z}/{x}/{y}.jpg";
    var layer=new ol.source.TileImage({
        projection: 'EPSG:4326',
        tileGrid: new ol.tilegrid.TileGrid({
            origin: ol.extent.getBottomLeft(new ol.proj.get("EPSG:4326").getExtent()),    // 设置原点坐标
            resolutions:[0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125,0.01953125, 0.009765625, 0.0048828125, 0.00244140625],
            extent: [-180, -90, 180, 90],
            tileSize:[256,256],
        }),
        wrapX:false,
        tileUrlFunction:function(tileCoord, pixelRatio, projection) {
            var z = tileCoord[0];
            var x = tileCoord[1];
            /*var y = Math.pow(2, z) + tileCoord[2];*/
            var y = tileCoord[2];
            // wrap the world on the X axis
            var n = Math.pow(2, z + 1); // 2 tiles at z=0
            x = x % n;
            if (x * n < 0) {
                // x and n differ in sign so add n to wrap the result
                // to the correct sign
                x = x + n;
            }
            return oUrl.replace('{z}', z.toString())
                .replace('{y}', y.toString())
                .replace('{x}', x.toString());
        },
    })
    var map = new ol.Map({
        layers: [
            //osmSource,
            /*new ol.layer.Tile({
                source: osmSource
            }),*/
            new ol.layer.Tile({
                source: layer
            }),
            new ol.layer.Tile({
                source: new ol.source.TileDebug({
                    projection: 'EPSG:4326',
                    tileGrid: layer.getTileGrid()
                })
            })

        ],
        target: 'map',
        controls: ol.control.defaults({
            attribution: false,
        }).extend([
            new ol.control.FullScreen(), //全屏
            new ol.control.MousePosition({
                undefinedHTML: 'outside',
                projection: 'EPSG:4326',
                coordinateFormat: function(coordinate) {
                    return ol.coordinate.format(coordinate, '{x}, {y}', 5);
                }
            }), //经纬度坐标
            /*new ol.control.OverviewMap(),*/ //鸟瞰图
            new ol.control.ScaleLine(), // 比例尺
            new ol.control.ZoomSlider(), //滚动轴
            new ol.control.ZoomToExtent(), //回到最大
        ]),
        view: new ol.View({
            projection: 'EPSG:4326',
            center: [116, 39],
            zoom: 4,
            minZoom: 0,
            maxZoom: 8,
            resolutions:[0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125,0.01953125, 0.009765625, 0.0048828125, 0.00244140625], //设置分辨率
            extent: [-180, -90, 180, 90]
        })
    });
</script>
</body>
</html>
点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消